<?php

import("data.db.DbAbstractTable");
import("data.db.DbFactory");
import("data.logic.property.UnitProperty");

class DbUnitProperty extends DbAbstractTable {
	
	//
	// SQL Table description section
	//
	const TB_TABLENAME	= "pd_unit_attr";
	const TB_I			= 'unita';
	
	const TB_NAME		= 'unita_name';
	const TB_DESCRIPT	= 'unita_descript';
	
	function _get_TABLENAME() {return self::TB_TABLENAME;}
	function _get_ID() {return self::TB_I."_id";}
	function _get_SUFFIX() {return self::TB_I;}
	//
	//
	
	// properties
	var $name;
	var $description;
	
	function DbUnitProperty() {
		parent::DbAbstractTable();
	}
	
	function getDisplayName() {
		return $this->lingvo->getValue($this->name);
	}
	
	function getName() {
		return $this->name;
	}
	function setName($name) {
		$this->name = $name;
	}
	
	function getDescription() {
		return $this->description;
	}
	function setDescription($desc) {
		$this->description = $desc;
	}
	
	function setUnit(&$unit) {
		$this->setForwardForeign('data.logic.product.Unit', $unit);
	}
	
	function getUnit() {
		$f = $this->getForwardForeign('data.logic.product.Unit');
		return $f->getForeign();
	}
	
	// restore
	function fillEntity($arrResult) {
		parent::fillEntity($arrResult);
		$this->setName($arrResult[self::TB_NAME]);
		$this->setDescription($arrResult[self::TB_DESCRIPT]);
		
		//Forward Foreigns
		$this->initForeign($arrResult, 'data.logic.product.Unit');
	}
	
	//store
	function fillFields() {
		parent::fillFields();
		$this->fildsForStore[self::TB_NAME] = "'".$this->getName()."'";
		$this->fildsForStore[self::TB_DESCRIPT] = "'".$this->getDescription()."'";
		
		$this->fildsAddForeign('data.logic.product.Unit');
	}
	
	// static find
	function findAll() {
		return parent::__selectAllByCriteria(
			null, 
			'data.logic.property.UnitProperty');
	}
	
	function findById($id) {
		return parent::__selectByCriteria(self::_get_ID()."='".$id."'", 'data.logic.property.UnitProperty');
	}
}
?>